// 导入并创建路由表
const querystring = require('querystring');
const router = require('express').Router();

// 模拟用户信息
let usersInfo = [
  {id:1,name:'zs',age:'1356124239',pass:123456,gender:28},
];
// 添加路由
// 获取所有用户信息
router.get('/list',(req,res)=>{
  res.send(usersInfo);
})
router.post('/add', (req, res) => {
    let str = "";
    req.on('data',(chunck)=>{str += chunck})
    req.on('end', () => {
        let user = querystring.parse(str)
        user.id = usersInfo.length + 1
        usersInfo.push(user)
        res.send(usersInfo)
    })
})
router.delete('/:id(\\d+)',(req,res)=>{
  // console.log(666)
  usersInfo =usersInfo.filter(v=>v.id != req.params.id)
  res.send(usersInfo)
})
module.exports = router;